package com.xh.bussiness.tiku.controller;

import com.xh.bussiness.tiku.bean.dto.QuestionCartDto;
import com.xh.bussiness.tiku.constant.QuestionConstant;
import com.xh.bussiness.tiku.service.IQuestionCartService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.constant.AjaxResultConstant;
import com.xh.core.controller.BaseController;
import com.xh.core.util.StringUtils;
import com.xh.core.util.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*
 * @Author daiwei
 * @Description
 * @Date 2019/3/18 13:34
 **/
@Api(tags="题库-试题篮接口")
@RestController
@RequestMapping("/tiku/questionCart")
public class QuestionCartController extends BaseController {

    private IQuestionCartService questionCartService;

    @PostMapping("/add")
    @ApiOperation(value="添加试题栏内容", notes = "添加试题栏内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name="cartType", value="试题栏类别（不传则默认分类）", required = false, dataType = "String"),
            @ApiImplicitParam(name="questionId", value="试题ID", required = true, dataType = "String"),
    })
    public AjaxResult add(String cartType,String questionId){
        if(StringUtils.isEmpty(cartType)){
            cartType= QuestionConstant.CART_TYPE.COMMON;
        }
        questionCartService.add(UserUtils.getCurrentUserId(), cartType, questionId);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"");
    }

    @PostMapping("/delete")
    @ApiOperation(value="删除试题栏内容", notes = "删除试题栏内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name="cartType", value="试题栏类别（不传则默认分类）", required = false, dataType = "String"),
            @ApiImplicitParam(name="questionId", value="试题ID", required = true, dataType = "String"),
    })
    public AjaxResult delete(String cartType,String questionId){
        if(StringUtils.isEmpty(cartType)){
            cartType= QuestionConstant.CART_TYPE.COMMON;
        }
        questionCartService.delete(UserUtils.getCurrentUserId(), cartType, questionId);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"");
    }

    @PostMapping("/deleteAll")
    @ApiOperation(value="清空试题栏内容", notes = "清空试题栏内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name="cartType", value="试题栏类别（不传则默认分类）", required = false, dataType = "String"),
    })
    public AjaxResult deleteAll(String cartType){
        if(StringUtils.isEmpty(cartType)){
            cartType= QuestionConstant.CART_TYPE.COMMON;
        }
        questionCartService.deleteAll(UserUtils.getCurrentUserId(), cartType);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"");
    }

    @PostMapping("/getByType")
    @ApiOperation(value="获取试题栏内容", notes = "获取试题栏内容")
    @ApiImplicitParams({
            @ApiImplicitParam(name="cartType", value="试题栏类别（不传则默认分类）", required = false, dataType = "String"),
    })
    public AjaxResult getByType(String cartType){
        if(StringUtils.isEmpty(cartType)){
            cartType= QuestionConstant.CART_TYPE.COMMON;
        }
        QuestionCartDto questionCartDto=questionCartService.getByCartType(UserUtils.getCurrentUserId(), cartType);
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS,"",questionCartDto);
    }
}
